home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIDIB.PAK / INFODLG.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  251 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   info.c
  9. //
  10. //  PURPOSE:   Displays the "Info" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdInfo        - Displays the "Info" dialog box
  14. //    InfoProc       - Processes messages for "Info" dialog box.
  15. //    MsgInfoInit    - To initialize the about box with version info
  16. //                     from resources.
  17. //    MsgInfoCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdInfoDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include "globals.h"            // prototypes specific to this application
  27. #include "infodlg.h"
  28.  
  29.  
  30. LRESULT CALLBACK InfoProc(HWND, UINT, WPARAM, LPARAM);
  31. LRESULT MsgInfoInit(HWND, UINT, WPARAM, LPARAM);
  32. LRESULT MsgInfoCommand(HWND, UINT, WPARAM, LPARAM);
  33. LRESULT CmdInfoDone(HWND, WORD, WORD, HWND);
  34.  
  35.  
  36. // Info dialog message table definition.
  37. MSD rgmsdInfo[] =
  38. {
  39.     {WM_COMMAND,    MsgInfoCommand},
  40.     {WM_INITDIALOG, MsgInfoInit}
  41. };
  42.  
  43. MSDI msdiInfo =
  44. {
  45.     sizeof(rgmsdInfo) / sizeof(MSD),
  46.     rgmsdInfo,
  47.     edwpNone
  48. };
  49.  
  50. // Info dialog command table definition.
  51. CMD rgcmdInfo[] =
  52. {
  53.     {IDOK,     CmdInfoDone},
  54.     {IDCANCEL, CmdInfoDone}
  55. };
  56.  
  57. CMDI cmdiInfo =
  58. {
  59.     sizeof(rgcmdInfo) / sizeof(CMD),
  60.     rgcmdInfo,
  61.     edwpNone
  62. };
  63.  
  64. // Module specific "globals"  Used when a variable needs to be
  65. // accessed in more than on handler function.
  66.  
  67.  
  68. //
  69. //  FUNCTION: CmdInfo(HWND, WORD, WORD, HWND)
  70. //
  71. //  PURPOSE: Displays the "Info" dialog box
  72. //
  73. //  PARAMETERS:
  74. //    hwnd      - Window handle
  75. //    wCommand  - IDM_INFO (unused)
  76. //    wNotify   - Notification number (unused)
  77. //    hwndCtrl  - NULL (unused)
  78. //
  79. //  RETURN VALUE:
  80. //
  81. //    Always returns 0 - Message handled
  82. //
  83. //  COMMENTS:
  84. //    To process the IDM_INFO message, call DialogBox() to display the
  85. //    InfoDlg dialog box.
  86.  
  87. #pragma argsused
  88. LRESULT CmdInfo(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  89. {
  90.     DialogBox(hInst, "InfoDlg", hwnd, (DLGPROC)InfoProc);
  91.     return 0;
  92. }
  93.  
  94.  
  95. //
  96. //  FUNCTION: InfoProc(HWND, UINT, WPARAM, LPARAM)
  97. //
  98. //  PURPOSE:  Processes messages for "Info" dialog box.
  99. //
  100. //  PARAMETERS:
  101. //    hdlg - window handle of the dialog box
  102. //    wMessage - type of message
  103. //    wparam - message-specific information
  104. //    lparam - message-specific information
  105. //
  106. //  RETURN VALUE:
  107. //    TRUE - message handled
  108. //    FALSE - message not handled
  109. //
  110. //  COMMENTS:
  111. //
  112. //     Display video device information
  113. //
  114. //     Wait for user to click on "Ok" button, then close the dialog box.
  115. //
  116.  
  117. LRESULT CALLBACK InfoProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  118. {
  119.     return DispMessage(&msdiInfo, hdlg, uMessage, wparam, lparam);
  120. }
  121.  
  122.  
  123. //
  124. //  FUNCTION: MsgInfoInit(HWND, UINT, WPARAM, LPARAM)
  125. //
  126. //  PURPOSE: To initialize the about box with version info from resources.
  127. //
  128. //  PARAMETERS:
  129. //    hwnd - The window handing the message.
  130. //    uMessage - The message number. (unused).
  131. //    wparam - Message specific data (unused).
  132. //    lparam - Message specific data (unused).
  133. //
  134. //  RETURN VALUE:
  135. //    Always returns 0 - message handled.
  136. //
  137. //  COMMENTS:
  138. //    Uses GetDeviceCaps to query the driver for info regarding
  139. //    the display device's color and palette capabilities.
  140. //
  141.  
  142. #pragma argsused
  143. LRESULT MsgInfoInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  144. {
  145.      HDC  hDC;
  146.      char szText[64];
  147.  
  148.     // Center the dialog over the application window
  149.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  150.  
  151.     // get screen DC
  152.     hDC = GetDC(NULL);
  153.     
  154.     // get various DeviceCaps
  155.     
  156.     // Palette-based device?
  157.     wsprintf(szText, "%s", (bPalDevice ? "Yes": "No"));
  158.     SetDlgItemText(hdlg, IDC_RCPALETTE, szText);
  159.  
  160.     if (bPalDevice)
  161.     {
  162.         wsprintf(szText, "%u", GetDeviceCaps(hDC, SIZEPALETTE));
  163.         SetDlgItemText(hdlg, IDC_SIZEPALETTE, szText);
  164.  
  165.         // This is the number of static colors reserved by Windows
  166.         wsprintf(szText, "%u", GetDeviceCaps(hDC, NUMRESERVED));
  167.         SetDlgItemText(hdlg, IDC_NUMRESERVED, szText);
  168.         
  169.         // This is the actual number of bits the device can use
  170.         // to represent colors. For example, the 8514/A uses
  171.           // 18 bit DACs: 6 bits for red, 6 for green, and 6 for blue.
  172.         wsprintf(szText, "%u", GetDeviceCaps(hDC, COLORRES));
  173.         SetDlgItemText(hdlg, IDC_COLORRES, szText);        
  174.     }
  175.     else
  176.     {
  177.         // not a palette device, so these aren't applicable
  178.         wsprintf(szText, "%s", "N/A");
  179.         SetDlgItemText(hdlg, IDC_SIZEPALETTE, szText);
  180.         SetDlgItemText(hdlg, IDC_NUMRESERVED, szText);
  181.         SetDlgItemText(hdlg, IDC_COLORRES, szText);
  182.     }
  183.  
  184.     wsprintf(szText, "%u", GetDeviceCaps(hDC, NUMCOLORS));
  185.     SetDlgItemText(hdlg, IDC_NUMCOLORS, szText);
  186.  
  187.     wsprintf(szText, "%u", GetDeviceCaps(hDC, BITSPIXEL));    
  188.     SetDlgItemText(hdlg, IDC_BITSPIXEL, szText);
  189.     
  190.     wsprintf(szText, "%u", GetDeviceCaps(hDC, PLANES));
  191.     SetDlgItemText(hdlg, IDC_PLANES, szText);
  192.                     
  193.     ReleaseDC(NULL, hDC);
  194.  
  195.      return TRUE;
  196. }
  197.  
  198. //
  199. //  FUNCTION: MsgInfoCommand(HWND, UINT, WPARAM, LPARAM)
  200. //
  201. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  202. //
  203. //  PARAMETERS:
  204. //    hwnd - The window handing the message.
  205. //    uMessage - The message number. (unused).
  206. //    wparam - Message specific data (unused).
  207. //    lparam - Message specific data (unused).
  208. //
  209. //  RETURN VALUE:
  210. //    Always returns 0 - message handled.
  211. //
  212. //  COMMENTS:
  213. //    Uses this DipsCommand function defined in wndproc.c combined
  214. //    with the cmdiInfo structure defined in this file to handle
  215. //    the command messages for the about dialog box.
  216. //
  217.  
  218. #pragma argsused
  219. LRESULT MsgInfoCommand(HWND   hwnd,
  220.                                 UINT   uMessage,
  221.                                 WPARAM wparam,
  222.                                 LPARAM lparam)
  223. {
  224.     return DispCommand(&cmdiInfo, hwnd, wparam, lparam);
  225. }
  226.  
  227. //
  228. //  FUNCTION: CmdInfoDone(HWND, WORD, HWND)
  229. //
  230. //  PURPOSE: Free the about box and related data.
  231. //
  232. //  PARAMETERS:
  233. //    hwnd - The window handling the command.
  234. //    wCommand - The command to be handled (unused).
  235. //    wNotify   - Notification number (unused)
  236. //    hwndCtrl - NULL (unused).
  237. //
  238. //  RETURN VALUE:
  239. //    Always returns TRUE.
  240. //
  241. //  COMMENTS:
  242. //    Calls EndDialog to finish the dialog session.
  243. //
  244.  
  245. #pragma argsused
  246. LRESULT CmdInfoDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  247. {
  248.     EndDialog(hdlg, TRUE);          // Exit the dialog
  249.     return TRUE;
  250. }
  251.